package com.rd.config.security;

import cn.hutool.json.JSONUtil;
import com.rd.common.CommonResult;
import com.rd.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 成功退出处理器
 */
@Slf4j
@Component
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request,
                                HttpServletResponse response,
                                Authentication authentication) throws IOException,
            ServletException {
        response.setContentType("application/json;charset=utf-8");
        log.info("退出成功!");
        CommonResult commonResult = ResultUtil.buildSuccess( "退出成功");
        response.getWriter().write(JSONUtil.toJsonStr(commonResult));
    }
}
